package com.caifu.mapper;

import com.caifu.pojo.SysRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 操作日志表 Mapper 接口
 * </p>
 *
 * @author tww
 * @since 2021-03-01
 */
public interface SysRecordMapper extends BaseMapper<SysRecord> {

    @Select(" <script>" +
            " select t.name, sh.shop_name, u.user_name, sh.org_id , date_format(s.created_time, '%Y-%m-%d %H:%i:%s') as created_time from sys_record s " +
            " left join sys_record_type t on s.label_id=t.CODE" +
            " left join ys_shop sh on s.shop_id=sh.id" +
            " left join sys_user u on s.sys_user_id=u.id" +
            " where 1=1" +
            " <if test='name != null and name != &quot;&quot;'>"+
            " and u.user_name like concat('%',#{name},'%')"+
            " </if>" +
            " <if test='startDay != null and startDay !=&quot;&quot; and endDay != null and endDay != &quot;&quot;'>"+
            " and date_format(s.created_time, '%Y%m%d%H%i%s')&gt;=#{startDay}  and date_format(s.created_time, '%Y%m%d%H%i%s')&lt;=#{endDay} "+
            " </if>" +
            "order by s.created_time desc limit #{page},#{num}" +
            " </script>")
    List<Map<String,Object>> pageRecord(@Param("page")long page, @Param("num")int num, @Param("name")String name, @Param("startDay")String startDay, @Param("endDay")String endDay);

    @Select(" <script>" +
            " select count(1) from sys_record s " +
            " left join sys_record_type t on s.label_id=t.CODE" +
            " left join ys_shop sh on s.shop_id=sh.id" +
            " left join sys_user u on s.sys_user_id=u.id" +
            " where 1=1" +
            " <if test='name != null and name != &quot;&quot;'>"+
            " and u.user_name like concat('%',#{name},'%')"+
            " </if>" +
            " <if test='startDay != null and startDay !=&quot;&quot; and endDay != null and endDay != &quot;&quot;'>"+
            " and date_format(s.created_time, '%Y%m%d%H%i%s')&gt;=#{startDay}  and date_format(s.created_time, '%Y%m%d%H%i%s')&lt;=#{endDay} "+
            " </if>" +
            "order by s.created_time" +
            " </script>")
    Long totalRecord(@Param("name")String name, @Param("startDay")String startDay, @Param("endDay")String endDay);
}
